<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/iconfont.css">
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="login.css">
    <script src="js/jquery-1.11.1.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="js/ip.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/gVerify.js"></script>
    <script src="js/bg.js"></script>
</head>
<body class="bg">
<canvas class="ball" id="left-ball"></canvas>
<canvas class="star-bg" id="starCanvas"></canvas>
<div class="logo">
    <p>计算机与通信工程学院</p>
</div>
<div class="login-box">
    <div class="logo-box">
        <p>欢迎来到算机与通信工程学院</p>
    </div>
    <form class="layui-form layui-form-pane" action="">

        <div class="layui-form-item">
            <div class="layui-input-inline">
                <input type="text" name="userNum" lay-verify="required" autocomplete="off" placeholder="请输入学号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <input type="password" name="password" placeholder="请输入密码" lay-verify="required|pass" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="radio" name="identity" value='1' lay-filter="test" title="管理员" style="color: #fff">
                <input type="radio" name="identity" value='0' lay-filter="test" title="学生">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <input type="text" id="code_input" name='codes' placeholder="请输入验证码" class="layui-input">
                <span id="v_container" style="float:left; width: 125px;height: 38px;"></span>
            </div>
        </div>
        <!--<div class="layui-input-block">-->
            <button class="layui-btn" lay-submit lay-filter="demo2">登录</button>
            <a href="login.html" class="layui-btn layui-btn-primary" style="float: right">注册</a>
            <p class="info" style="text-align: center; color: #fff;"></p>
        <!--<button class="layui-btn layui-btn-primary" type="reset" style="float: right">重置</button>-->
        <!--</div>-->
        <!--<p class="info" style="text-align: center; color: #fff;">忘记密码<a href="2主页面背景1.html" class="login">点击找回密码</a></p>-->
    </form>
</div>


<script>
$(function(){
    var verifyCode = new GVerify({
        id: 'v_container',
        type: 'number'
    });
    layui.use(['layer','form','laypage','element'], function(){

        var $ = layui.jquery,
            layer = layui.layer,
            element = layui.element,
            form=layui.form,
            laypage=layui.laypage;
            
        form.on('submit(demo2)', function (data) {
            if (!$.trim($('#code_input').val())) {
                layer.msg('请输入验证码！');
            } else {
                if (verifyCode.validate($('#code_input').val())) {
                    console.log(data.field);
                    $.ajax({
                        type: "POST",
                        data: {
                            number: data.field.userNum,
                            password: data.field.password,
                            admin: data.field.identity
                        },
                        url: api+"login",
                        success: function(result){
                            console.log(result);
                            if(result.code == 1){
                            	if(data.field.identity == 0){
									  $.cookie('tokenM', result.message, { expires: 7, path: '../' });
									  $.cookie('tokenMyNum', data.field.userNum, { expires: 7, path: '../' });
//									  console.log($.cookie('tokenMyNum'));
	                                  location.href = 'manager/page/login/login.html';
                            	}else if(data.field.identity == 1){
									  $.cookie('tokenA', result.message, { expires: 7, path: '../' });
									  $.cookie('tokenAdNum', data.field.userNum, { expires: 7, path: '../' });
//									  console.log($.cookie('tokenAdNum'));
	                                  location.href = 'manager-wm/index.html';
                            	}

                            }else{
                                layer.msg(result.message);
//                              $('.info').html(result.message);
                            }
                        }
                    })
                } else {
                    layer.msg('验证码错误！');
                }
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        return false;
    });
});
</script>
</body>
</html>